package com.t4.courseware.controller;

import com.t4.courseware.common.Result;
import com.t4.courseware.pojo.dto.CoursewareDto;
import com.t4.courseware.service.CoursewareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


@RestController
@RequestMapping("courseware")
public class CoursewareController {

    @Autowired
    private CoursewareService coursewareService;

    @GetMapping("/list")
    public Result listCourseWare(@RequestParam Integer start) {
        return coursewareService.list(start);
    }

    @PostMapping("uploadCover")
    public Result uploadCover(@RequestParam("img") MultipartFile multipartFile){
        return coursewareService.uploadCover(multipartFile);
    }

    @PostMapping("uploadResource")
    public Result uploadResource(@RequestParam("file") MultipartFile multipartFile){
        return coursewareService.uploadResource(multipartFile);
    }

    @PostMapping("upload")
    public Result upload(@RequestBody CoursewareDto coursewareDto){
        return coursewareService.upload(coursewareDto);
    }


    @GetMapping("search")
    public Result search(@RequestParam(required = true) String key){
        return coursewareService.search(key);
    }
}
